/*
 * @lc app=leetcode id=73 lang=cpp
 *
 * [73] Set Matrix Zeroes
 */
class Solution {
public:
    void setZeroes(vector<vector<int>>& matrix) {
        int row = matrix.size();
        if (row < 1) {
            return;
        }

        int col = matrix[0].size();

        vector<bool> visitedCol(col, false);
        vector<bool> visitedRow(row, false);

        for (int i=0; i<row; i++) {
            if (visitedRow[i])
                continue;
            for (int j=0; j<col; j++) {
                if (matrix[i][j] == 0) {
                    visitedRow[i] = true;
                    visitedCol[j] = true;
                }
            }
        }

        for (int i=0; i<row; i++) {
            if (visitedRow[i]) {
                for (int j=0; j<col; j++) {
                    matrix[i][j] = 0;
                }
            }
        }
        for (int j=0; j<col; j++) {
            if (visitedCol[j]) {
                for (int i=0; i<row; i++) {
                    matrix[i][j] = 0;
                }
            }
        }
    }
};

